package com.xiaofeng.springboot.async;

import java.util.concurrent.Future;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

/**
 * 
 * @author chenzf
 * @date 2017年7月28日
 */
@Component
@SuppressWarnings("static-method")
public class AsyncTask {

	@Async
	public void doTaskOne() throws InterruptedException {
		Thread.sleep(6000);
		System.out.println("异步执行任务1");
	}

	@Async
	public void doTaskTwo() throws InterruptedException {
		Thread.sleep(6000);
		System.out.println("异步执行任务2");
	}

	@Async
	public void doTaskThree() throws InterruptedException {
		Thread.sleep(6000);
		System.out.println("异步执行任务3");
	}

	@Async
	public Future<String> doFutureTaskOne() throws InterruptedException {
		Thread.sleep(6000);
		System.out.println("异步执行有返回任务1");
		return new AsyncResult<String>("");
	}

	@Async
	public Future<String> doFutureTaskTwo() throws InterruptedException {
		Thread.sleep(6000);
		System.out.println("异步执行有返回任务2");
		return new AsyncResult<String>("");
	}

	@Async
	public Future<String> doFutureTaskThree() throws InterruptedException {
		Thread.sleep(6000);
		System.out.println("异步执行有返回任务3");
		return new AsyncResult<String>("");
	}
}
